package com.gary.prometheus.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author peng_rui
 * @date 2022/8/26
 */
@Slf4j
@Aspect
@Component
public class LogAspect {

    @Pointcut("within(@org.springframework.web.bind.annotation.RestController *)")
    public void toRestController() {
    }

    @Around("toRestController()")
    public Object enhance(ProceedingJoinPoint pjp) {
        System.out.println("enhance...");
        try {
            pjp.proceed();
        } catch (Throwable throwable) {
            log.error(throwable.getMessage(), throwable);
        }
        return null;
    }

    @Around("execution(* com.gary.prometheus.controller.AspectController.*())")
    public void around(ProceedingJoinPoint pjp) {
        System.out.println("enhance...");
        try {
            pjp.proceed();
        } catch (Throwable throwable) {
            log.error(throwable.getMessage(), throwable);
        }
    }

    public static void main(String[] args) {

        boolean b1 = true;

        char c1 = '打';

        byte ic1 = (byte) c1;

        double db = ic1;

        System.out.println("db "+db);

        System.out.println("ic1 "+ic1);


        System.out.println(Integer.MAX_VALUE);
        System.out.println(Long.MAX_VALUE);

        int i1 = Integer.MAX_VALUE;
        long l1 = Long.MAX_VALUE;

        i1 = (int) l1;
        System.out.println(i1);

        int i2 = Integer.MAX_VALUE;
        long l2 = Long.MAX_VALUE;

        l2 = i2;
        System.out.println(l2);
        System.out.println("************************");

        System.out.println(Double.MAX_VALUE);
        System.out.println(Float.MAX_VALUE);

        double d1 = Double.MAX_VALUE;
        float f1 = Float.MAX_VALUE;

        double d2 = Double.MAX_VALUE;
        float f2 = Float.MAX_VALUE;
        f1 = (float) d1;
        d2 = f2;
        System.out.println(f1);
        System.out.println(d2);
    }
}
